#if PocketPC
using System;
using System.Runtime.InteropServices;
using System.Text;

namespace GeoFramework.Licensing
{
#if !PocketPC && Framework20
    [SuppressUnmanagedCodeSecurity]
#endif
    internal 
#if Framework20
	static
#else
		sealed
#endif
		class NativeMethods
    {
        public static IntPtr GetModuleHandle(IntPtr hModule)
        {
#if PocketPC
            if (Environment.OSVersion.Platform == System.PlatformID.WinCE)
            {
                return GetModuleHandleCompact(hModule);
            }
            else
#endif
                return GetModuleHandleDesktop(hModule);
        }

        public static int GetModuleFileName(IntPtr hModule, StringBuilder lpFilename, int nSize)
        {
#if PocketPC
            if (Environment.OSVersion.Platform == System.PlatformID.WinCE)
            {
                return GetModuleFileNameCompact(hModule, lpFilename, nSize);
            }
            else
#endif
                return GetModuleFileNameDesktop(hModule, lpFilename, nSize);
        }

        #region Compact Frmaework P/Invokes 

        [DllImport("coredll.dll", EntryPoint = "GetModuleHandle", SetLastError = true)]
        private static extern IntPtr GetModuleHandleCompact(IntPtr hModule);

        [DllImport("coredll.dll", EntryPoint="GetModuleFileName", SetLastError = true)]
        private static extern Int32 GetModuleFileNameCompact(IntPtr hModule, StringBuilder lpFilename, Int32 nSize);

        #endregion

        #region Desktop Framework P/Invokes

        [DllImport("kernel32.dll", EntryPoint = "GetModuleHandle", SetLastError = true)]
        private static extern IntPtr GetModuleHandleDesktop(IntPtr hModule);

        [DllImport("kernel32.dll", EntryPoint = "GetModuleFileName", SetLastError = true)]
        private static extern Int32 GetModuleFileNameDesktop(IntPtr hModule, StringBuilder lpFilename, Int32 nSize);

        #endregion
    }
}
#endif